package com.youhome.response;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.Collections;
import java.util.List;

/**
 * Created by chen365 on 2017/10/18.
 */
@Data
public class ResultPage<T> {

    private Integer status; //状态

    private String msg;  //提示信息

    private Long total=0L; //总条数

    private Integer pageSize;  //每页条数

    private Integer totalPages; //总页数

    private Integer currentPage; //当前页

    private List<Object> rows = Collections.emptyList(); //数据

    public ResultPage() {
    }

    public ResultPage(Integer status, String msg, PageInfo pageInfo) {
        this.status = status;
        this.msg = msg;
        this.total = pageInfo.getTotal();
        this.pageSize = pageInfo.getPageSize();
        this.totalPages = pageInfo.getPages();
        this.currentPage = pageInfo.getPageNum();
        this.rows = pageInfo.getList();
    }

    public ResultPage(ResultCode resultCode, PageInfo pageInfo) {
        this.status = resultCode.getStatus();;
        this.msg = resultCode.getMsg();;
        this.total = pageInfo.getTotal();
        this.pageSize = pageInfo.getPageSize();
        this.totalPages = pageInfo.getPages();
        this.currentPage = pageInfo.getPageNum();
        this.rows = pageInfo.getList();
    }

    public ResultPage(ResultCode resultCode) {
        this.status = resultCode.getStatus();
        this.msg = resultCode.getMsg();
    }
}
